/*
 * =====================================================================================
 *
 *       Filename:  3664heap.c
 *
 *    Description:  use heap to solve the top k problem
 *
 *        Version:  1.0
 *        Created:  2012年06月28日 15时44分54秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Regan (), lcqhigh@gmail.com
 *        Company:
 *
 * =====================================================================================
 */
#include	<stdio.h>
#include	<stdlib.h>

static int v1[50001];
static int v2[50001];
static int *ptrs[50001];

//should be a min heap
void shift_down(int s, int m)
{
    int j = (s << 1) + 1;
    int *p = ptrs[s];
    while (j <= m) {
        if (j < m && *ptrs[j+1] < *ptrs[j])
            ++j;
        if (*p > *ptrs[j]) {
            ptrs[s] = ptrs[j];
            s = j;
            j = (s << 1) + 1;
        } else
            break;
    }
    ptrs[s] = p;
    return;
}


int main(int argc, char *argv[])
{
    int n, k;
    int i, winidx = 0;
    while (scanf("%d %d", &n, &k) == 2) {
        for (i = 0; i < n; ++i)
        {
          scanf("%d %d", &v1[i], &v2[i]);
          //ignore this is wrong
          ptrs[i] = &v1[i];
        }
        //create the heap
        for (i = (k-2)/2; i >= 0; --i)
        {
           shift_down(i, k-1);
        }
        for (i = k; i < n; ++i)
        {
            if (*ptrs[i] > *ptrs[0])
            {
                ptrs[0] = ptrs[i];
                shift_down(0, k-1);
            }
        }

        winidx = 0;
        for (i = 1; i < k; ++i)
        {
            if (v2[(ptrs[i]-v1)] > v2[(ptrs[winidx]-v1)])
                winidx = i;
        }
        printf ( "%lu\n",(ptrs[winidx]-v1)+1);
    }
    return 0;
}
